<template>
	<view>
		<view class="title-header">
			<input type="text" placeholder="请输入作业名" v-model="homeworkTaskName">
		</view>
		<view class="example-body">
			<uni-datetime-picker v-model="single" @change="timeChange">
				<view class="input" v-show="!showTime">
					{{timeText}}
					<uni-icons type="right" size="22"></uni-icons>
				</view>
			</uni-datetime-picker>
		</view>
		<view class="textarea">
			<textarea placeholder="作业简述(不能超过200字)" v-model="content" />
		</view>
		<button type="primary" @click="submit">发布</button>
	</view>
</template>

<script>
	import server from '@/util/http.js'
	export default {
		data() {
			return {
				showTime: false,
				index: [],
				single: '',
				timeText: '请选择截止时间',
				homeworkTaskName: '',
				content: '',
				tid: '',
				onlineClassId: ''
			}
		},
		onLoad(option) {
			this.onlineClassId = option.id
		},
		methods: {
			//列改变时 课程列表
			columnChange(e) {
				//console.log(e);
			},
			timeChange(e) {
				this.timeText = e;
			},
			submit() {
				let startTime = new Date().toLocaleString();
				uni.getStorage({
					key: 'teacher',
					success: (res) => {
						this.tid = res.data.id
					}
				})
				server({
					url: 'http://101.43.227.220:3003/teacher/publishHomework',
					method: 'post',
					data: {
						"onlineClassId": Number(this.onlineClassId),
						"homeworkTaskName": this.homeworkTaskName,
						"tid": Number(this.tid),
						"startTime": startTime,
						"stopTime": this.timeText,
						"content": this.content
					},
					success: res => {
						uni.showToast({
							title: '发布成功',
							duration: 2000
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 2000)

					}
				})
			}
		}
	}
</script>

<style scoped>
	.textarea textarea {
		padding: 8px;
		width: 90%;
		margin: 20px auto;
		font-weight: 500;
		border-radius: 5px;
		font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
		border: 1px solid lightgray;
	}

	.title-header input {
		padding: 8px;
		width: 90%;
		margin: 20px auto;
		font-weight: 500;
		font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
	}

	.input {
		padding: 8px;
		width: 90%;
		margin: 0 auto;
		margin-top: 20px;
		font-weight: 500;
		font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
	}

	>>>.uni-icons {
		float: right;
	}

	button {
		width: 90%;
		margin-top: 40px;
	}
</style>
